home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilwb / filesiz2.lha / FileSize / id.c < prev   
C/C++ Source or Header  |  1997-01-12  |  2KB  |  145 lines

  1. #include <stdio.h>
  2. #include <proto/datatypes.h>
  3. #include <proto/exec.h>
  4. #include <proto/dos.h>
  5.  
  6. char *id(char *buf,char *fname);
  7. char *id2(char *buf, char *fname);
  8. char *strippath(char *name);
  9.  
  10. char *id(char *buf,char *fname) {
  11.     struct DataType *dtn;
  12.     struct DataTypeHeader *dth;
  13.     BPTR lock;
  14.     
  15.     strcpy(buf,"");
  16.     
  17.     if(lock=Lock(fname,ACCESS_READ)) {    
  18.         if(dtn=ObtainDataTypeA(DTST_FILE,(APTR)lock,0)) {
  19.             dth=dtn->dtn_Header;
  20.             
  21.             sprintf(buf,"%s ",dth->dth_Name);
  22.             
  23.             switch(dth->dth_GroupID) {
  24.                 char b2[1000];
  25.                 
  26.                 case GID_SYSTEM:
  27.                     /* This is a bit of a catch all so lets see if
  28.                        we can id it other ways */
  29.                        
  30.                     if(strcmp(id2(b2,fname),""))
  31.                         strcpy(buf,b2);
  32.                     else
  33.                         strcat(buf,"system file");    
  34.                 break;
  35.                 case GID_TEXT:
  36.                     strcat(buf,"text file");    
  37.                 break;
  38.                 case GID_DOCUMENT:
  39.                     strcat(buf,"document");    
  40.                 break;
  41.                 case GID_SOUND:
  42.                     strcat(buf,"Sound Sample");    
  43.                 break;
  44.                 case GID_INSTRUMENT:
  45.                     strcat(buf,"instrument");    
  46.                 break;
  47.                 case GID_MUSIC:
  48.                     strcat(buf,"music score");    
  49.                 break;
  50.                 case GID_PICTURE:
  51.                     strcat(buf,"Picture");    
  52.                 break;
  53.                 case GID_ANIMATION:
  54.                     strcat(buf,"Animation");    
  55.                 break;
  56.                 case GID_MOVIE:
  57.                     strcat(buf,"Movie");    
  58.                 break;
  59.             }
  60.             
  61.             ReleaseDataType(dtn);
  62.         } else
  63.             buf=0;
  64.         UnLock(lock);
  65.     } else 
  66.         buf=0;    
  67.     
  68.     return(buf);
  69. }
  70.  
  71.  
  72. char *id2(char *buf, char *fname) {
  73.     FILE *fp=0;
  74.     char tmp[100];
  75.     char byte;
  76.     char mem[1000];
  77.     
  78.     strcpy(mem,fname);
  79.     
  80.     strcpy(buf,"");
  81.     
  82.     if(fp=fopen(fname,"r")) {
  83.         /* Read header */
  84.         
  85.         fread(tmp,99,1,fp);
  86.         
  87.         byte=tmp[4];
  88.         tmp[4]=0;
  89.         if(!(strcmp(tmp,"MMD0"))) {
  90.             strcpy(buf,"MED Music Module");
  91.             goto end;
  92.         }
  93.         if(!(strcmp(tmp,"MMD1"))) {
  94.             strcpy(buf,"MED Music Module");
  95.             goto end;
  96.         }
  97.         if(!(strcmp(tmp,"MMD2"))) {
  98.             strcpy(buf,"OctaMED Music Module");
  99.             goto end;
  100.         }
  101.         if(!(strcmp(tmp,"MThd"))) {
  102.             strcpy(buf,"MIDI Music File");
  103.             goto end;
  104.         }
  105.         tmp[4]=byte;
  106.  
  107.         strippath(fname);
  108.  
  109.         byte=fname[4];
  110.         fname[4]=0;
  111.         strlwr(fname);
  112.         if(!(strcmp(fname,"mod."))) {
  113.             strcpy(buf,"Tracker Music Module");
  114.             goto end;
  115.         }
  116.         fname[4]=byte;
  117.         
  118.         
  119.     }
  120.  
  121.     end:
  122.     if(fp) fclose(fp);
  123.     strcpy(fname,mem);
  124.     return(buf);
  125. }
  126.  
  127. char *strippath(char *name) {
  128.     
  129.     long count,i;
  130.     char tmp[1000];
  131.     
  132.     count=strlen(name);
  133.  
  134.     for(i=count; i>=0; i--) {
  135.         if(name[i]=='/' || name[i]==':') {
  136.             strcpy(tmp,&name[i+1]);
  137.             strcpy(name,tmp);
  138.             return(name);
  139.         }
  140.         
  141.     }
  142.     
  143.     printf("strip = %s\n",name);
  144.     return(name);
  145. }